package com.sto.stoapp.manager;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetWorkManager {

	private static NetWorkManager manager;

	// 网络实现类
	private ConnectivityManager conMan;

	// 网络状态
	private NetworkInfo mobNetInfo;


	private Context context;

	/**
	 * 构造函数
	 * 
	 * @param context
	 *            上下文
	 */
	private NetWorkManager(Context context) {
		conMan = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		mobNetInfo = conMan.getActiveNetworkInfo();
		this.context = context;
	}

	/**
	 * 单例化对象
	 * 
	 * @param context
	 *            上下文
	 * @return
	 */
	public static NetWorkManager getInstance(Context context) {
		if (manager == null) {
			manager = new NetWorkManager(context);
		}
		return manager;
	}

	/**
	 * GPRS模块是否可用
	 * 
	 * @return
	 */
	public boolean isGprsModule() {
		if (mobNetInfo != null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * GPRS模块是否打开
	 * 
	 * @return
	 */
	public boolean isOpenGprs() {
		if (mobNetInfo != null) {
			if (mobNetInfo.isConnected()
					&& mobNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}




}
